//
//  GRTransitionAnimator.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/8/6.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRTransitionAnimator.h"
static NSTimeInterval const kDefaultDuration = 1.0;
@implementation GRTransitionAnimator
-(instancetype)init{
    if (self = [super init]) {
        _duration = kDefaultDuration;
    }
    return self;
}

#pragma mark - UIViewControllerAnimatedTransitioning

// This is used for percent driven interactive transitions, as well as for
// container controllers that have companion animations that might need to
// synchronize with the main animation.
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext
{
    return self.duration;
}


// This method can only  be a nop if the transition is interactive and not a percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *fromView = fromVC.view;
    UIView *toView = toVC.view;
    UIView *containerView = [transitionContext containerView];
    NSTimeInterval duration = [self transitionDuration:transitionContext];
     [containerView addSubview:toView];
    [containerView bringSubviewToFront:fromView];
    [UIView animateWithDuration:duration animations:^{
         fromView.alpha = 0.0;
          toView.alpha = 1.0;
        } completion:^(BOOL finished) {
             [transitionContext completeTransition:YES];
        }];
 
    
}


@end
